<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Config;
use think\Db;
use think\Request;

/**
 * 预约相关
 */
class Yuyue extends Api
{

    // 无需登录的接口,*表示全部
    protected $noNeedLogin = [];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    public function applys(){

        $user=$this->auth->getUser();


        $log['user_id']=$user['id'];
        $log['day']=$this->request->param('date');
        $log['time']=$this->request->param('times');
        $log['sf']=$this->request->param('sf');

        $find=Db::name('yuyue')->where($log)->count();

        if ($find>2){
            $this->error('当前时间不可使用！',$find);
        }


        $log['nickname']=$this->request->param('name');
        $log['mobile']=$this->request->param('mobile');
        foreach ($log as $key=>$kv){
            if (!$kv){
                $this->error('请填写完整信息！');
            }
        }




        Db::name('yuyue')->data($log)->insert();


        $this->success('操作成功！');


    }


    /**
     * 加分申请
     */
    public function jiafen(){
        $user=$this->auth->getUser();

        $log['name']=$this->request->param('name');
        $log['mobile']=$this->request->param('mobile');
        $log['text']=$this->request->param('text');
        $log['leibie']=$this->request->param('leibie');
        $log['desc']=$this->request->param('desc');

        $log['user_id']=$user['id'];
        Db::name('jiafen')->data($log)->insert();

        $this->success('提交成功！');


    }




    /**
     * 首页换灯片
     */
    public function getbanner()
    {

        $groupid=$this->auth->group_id;


        $banner=Db::name('banner')->where(['status'=>1])
            ->where('user_group_ids','like','%'.$groupid.'%')
            ->select();

        foreach ($banner as &$key){

            $key['image']=cdnurl($key['image'],true);
        }

        $this->success('请求成功!'.date('Y-m-d H:i'),$banner);
    }


    public function yuyuecate()
    {

        $banner=Db::name('yuyue_cate')
            ->find();


        $list=explode(',',$banner['desc']);


        $this->success('请求成功!'.date('Y-m-d H:i'),$list);
    }

}



